package de.clapp.club;

import java.util.ArrayList;

import android.content.AsyncTaskLoader;
import android.content.Context;
import de.clapp.backend.network.ClientRequest;
import de.clapp.backend.network.TCPSocket;
import de.clapp.backend.requests.ClubRequest;
import de.clapp.data.Club;
import de.clapp.data.settings.ServerSettings;



public class ClubListLoader extends AsyncTaskLoader<ArrayList<Club>>
{
    private ArrayList<Club> clubList;

    public ClubListLoader(Context context)
    {
        super(context);
    }
    

    @Override
    public ArrayList<Club> loadInBackground()
    {
        ClubRequest request = new ClubRequest();
        // Serververbindung
        try
        {
            System.out.println("ClubListLoader.loadInBackground() 1");
            ClientRequest r = new ClientRequest(new TCPSocket(de.clapp.Settings.ServerIP, ServerSettings.ServerPort));
            System.out.println("ClubListLoader.loadInBackground() 2");
            r.request(request);
            System.out.println("ClubListLoader.loadInBackground() 3");
            clubList = request.getItem();
            r.close();
            System.out.println("ClubListLoader.loadInBackground() 4");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        
        return clubList;
    }
}